<template>
  <main>
    <!-- 标题 -->
     <h1 style="text-align: center;">首页</h1>
    <!-- 导航区 -->
    <div style="text-align: center;">
    
    </div>
    <!-- 内容呈现 -->
    <div class="custom-content">
        <p>钱：{{ money }} 只读钱：{{ moneyReadOnly }}</p>
        <button @click="updateMoney">修改钱</button>
        <button @click="updateMoneyReadOnly">修改只读钱</button>
        <p>名字：{{ person.name }} 车：{{ person.car }}</p>
        <p>以下为只读</p>
        <p>名字：{{ personReadOnly.name }} 车：{{ personReadOnly.car }}</p>
        <button @click="updateName">修改名字</button>
        <button @click="updateColor">修改车颜色</button>
        <button @click="updatePrice">修改车价格</button>
    </div>
  </main>
</template>

<script lang="ts">
export default {
  name: 'App'
}
</script>

<script setup lang="ts">
import { reactive, readonly, ref, shallowReadonly } from 'vue';


let money = ref(0)
let moneyReadOnly = readonly(money)

function updateMoney() { 
  money.value+=10
}
//修改不了，因为是只读的
function updateMoneyReadOnly() { 
  moneyReadOnly.value+=10
}

let person = reactive({ name: 'zs', car: { color: 'green', price: 100 } })
//设置只读属性
let personReadOnly = shallowReadonly(person)

//最顶层修改不了数据，因为用了shallowReadonly，深层次的数据都可以修改
function updateName() { 
  personReadOnly.name = 'ww'
}

function updateColor() { 
  personReadOnly.car.color = 'black'
}

function updatePrice() { 
  personReadOnly.car.price = 10
}

</script>

<style lang="css">
.custom-a {
  display: inline-block;
  width: 50px;
  height: 20px;
  border: 1px solid black;
  margin-right: 50px;
  text-align: center;
  background-color: aqua;
}

.custom-a a {
  text-decoration: none;
  display: block;
  width: 50px;
  height: 20px;
}

.custom-content {

  margin: 0 auto;
  margin-top: 20px;
  border: 1px solid black;
  height: 700px;
  width: 1000px;
}

.custom-active {
  background-color: red;
}
</style>
